package com.bishe.service.impl;

import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bishe.entity.ClaTeacher;
import com.bishe.entity.QualityType;
import com.bishe.entity.resp.CommonPageRequest;
import com.bishe.entity.resp.CommonSortOrderEnum;
import com.bishe.entity.resp.PageParam;
import com.bishe.mapper.QualityTypeMapper;
import com.bishe.service.QualityTypeService;
import org.springframework.stereotype.Service;

/**
* @author wwz
* @description 针对表【quality_type】的数据库操作Service实现
* @createDate 2024-04-03 23:14:54
*/
@Service
public class QualityTypeServiceImpl extends ServiceImpl<QualityTypeMapper, QualityType>
    implements QualityTypeService {

    @Override
    public Page<QualityType> page(PageParam pageParam) {
        QueryWrapper<QualityType> queryWrapper = new QueryWrapper<>();
        if (ObjectUtil.isAllNotEmpty(pageParam.getSearchKey(), pageParam.getSearchValue())) {
            queryWrapper.eq(true, StrUtil.toUnderlineCase(pageParam.getSearchKey()), pageParam.getSearchValue());
        }

        if(ObjectUtil.isAllNotEmpty(pageParam.getSortField(), pageParam.getSortOrder())) {
            CommonSortOrderEnum.validate(pageParam.getSortOrder());
            queryWrapper.orderBy(true, pageParam.getSortOrder().equals(CommonSortOrderEnum.ASC.getValue()),
                    StrUtil.toUnderlineCase(pageParam.getSortField()));
        } else {
            queryWrapper.lambda().orderByAsc(QualityType::getId);
        }
        return this.page(CommonPageRequest.defaultPage(), queryWrapper);
    }
}




